Fix TypePreinit preinitialization correctness#128973
Merged
MichalStrehovsky merged 3 commits intoJun 8, 2026
Merged
Conversation
Intern foreign preinit instances so nested static reference identity is preserved, conservatively mark serialized object instances mutable, and fix vtable-like slot clearing. Add NativeAOT smoke coverage for nested preinit identity and vtable slot clearing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the NativeAOT type preinitialization interpreter/serializer to preserve reference identity across nested preinit evaluation, fix a vtable-like slot initialization bug, and make frozen object mutability tracking more conservative. It also adds smoke-test coverage for the identity and slot-clearing scenarios.
Changes:
- Intern
ForeignTypeInstanceobjects by allocation site so repeated references to the same nested-preinit allocation preserve identity. - Fix vtable-like slot clearing to null out the correct range of slots.
- Make serialized
ObjectInstanceconservatively reportIsKnownImmutable => false, and add NativeAOT smoke tests for nested identity + slot clearing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/tests/nativeaot/SmokeTests/Preinitialization/Preinitialization.cs | Adds new smoke tests for nested preinit identity and vtable-slot clearing behavior. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs | Fixes correctness in nested preinit object identity, vtable-like slot clearing, and mutability classification. |
jkotas
approved these changes
Jun 4, 2026
MichalStrehovsky
commented
Jun 4, 2026
This was referenced Jun 5, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I asked GPT-5.5 to find bugs and it found bugs. One is more severe.
Intern foreign preinit instances so nested static reference identity is preserved, conservatively mark serialized object instances mutable, and fix vtable-like slot clearing.
Add NativeAOT smoke coverage for nested preinit identity and vtable slot clearing.